﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Configuration;
using KPIS.DBM;
using KPIS.GERP.GIMS.MODEL;

namespace KPIS.GERP.GIMS.DAL
{
    public class UserDAL
    {
        IDBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);

        public DataSet Login(string Code, string Password)
        {
            string strSQL;
            DataSet ds;

            try
            {
                dbManager.Open();
                dbManager.CreateParameters(2);

                dbManager.AddParameters(0, "@name", Code);
                dbManager.AddParameters(1, "@password", Password);

                strSQL = "SELECT *"
                        + ", cast(concat(user_first_name, ' ', user_last_name) as char) as user_name"
                        + " FROM SYS_SC_USERS"
                        + " WHERE USER_CODE = @name"
                            + " AND USER_PASSWORD = @password";

                ds = dbManager.ExecuteDataSet(CommandType.Text, strSQL);

            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return ds;
        }
    }
}
